package com.ayuan.blog.service.impl;

import org.apache.commons.collections.CollectionUtils;
import org.durcframework.core.expression.ExpressionQuery;
import org.durcframework.core.expression.subexpression.ValueExpression;
import org.durcframework.core.service.CrudService;
import com.ayuan.blog.service.AccountService;
import com.ayuan.blog.dao.AccountDao;
import com.ayuan.blog.domain.Account;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AccountServiceImpl 
        extends CrudService<Account, AccountDao> 
        implements AccountService {

    @Override
    public Account checkAccountAndPassword(String account, String password) {
        ExpressionQuery query = new ExpressionQuery();
        query.add(new ValueExpression("account", account));
        query.add(new ValueExpression("password", password));

        List<Account> accountList = this.getDao().find(query);

        if (CollectionUtils.isNotEmpty(accountList)) {
            return accountList.get(0);
        } else {
            return null;
        }
    }
}